<template>
  <div id="">
      <ul class="allocationList">
        <li v-for="(item,index) in housingAllocation"
        :key="item.key"
        @click="chooseList(index)">
          <span>{{item.configName}}</span>
          <img src="@/assets/images/true@2x.png" width="15" alt="" v-if="item.isChoose">
        </li>
      </ul>
    <div class="fixedBottom">
      <button type="button" name="button" class="blockBtn" @click="chooseAllocation">确定</button>
    </div>
  </div>
</template>
<script>
export default {
  name: "",
  data: () => ({
    housingAllocation:[],
    idx:0,
    popupVisible:true,
    chooseHouseAct:[],    //存储选中的配置对象id
    chooseHouseActName:[],  //存储选择的配置对象名称
  }),
  methods: {
    chooseList(index) {
      var that = this;
      var chooseArr = new Array();
      var housingAllocation = that.housingAllocation;
      // console.log(housingAllocation);
      for (var i=0; i<housingAllocation.length; i++) {
        chooseArr[i] = housingAllocation[i].isChoose;
      }
      housingAllocation[index].isChoose = !chooseArr[index];
      if(housingAllocation[index].isChoose){
        that.chooseHouseAct.push(housingAllocation[index].configId);
        that.chooseHouseActName.push(housingAllocation[index].configName)
      }else{
        let chooseHouseAct = that.chooseHouseAct;
        let chooseHouseActName = that.chooseHouseActName;
        for (var j = 0; j < chooseHouseAct.length; j++) {
          if(chooseHouseAct[j]==housingAllocation[index].configId){
            chooseHouseAct.splice(j,1);
            chooseHouseActName.splice(j,1);
          }
        }
        that.chooseHouseAct = chooseHouseAct;
        that.chooseHouseActName = chooseHouseActName;
      }

      that.housingAllocation = housingAllocation;
    },
    chooseAllocation(){
      let that = this;
      this.$emit('houseAllocation',{
        chooseHouseAct:that.chooseHouseAct,
        chooseHouseActName:that.chooseHouseActName
      });
    },


  },
  mounted() {
    //do something after mounting vue instance
    let that = this;
    network.get(configUrl.HOUSECONFIG_URL,'',function(res){
      console.log(res);
      var dataList = res.dataList
      for (var i = 0; i < dataList.length; i++) {
        dataList[i].isChoose = false;
      }
      that.housingAllocation = dataList;
    },function(err){
      console.log(err);
    });
  },
  created() {

  }
}
</script>
<style lang="scss" scoped>

.allocationList{
  padding: 0 10px;
  font-size: 1rem;
  li{
    @include flex;
    justify-content: space-between;
    line-height: 3rem;
    border-bottom: 1px solid $borderColor;

  }
}
</style>
